<?php

//require_once 're/Type/Scalar.php';
require_once 'standard/re/Scalar.php';
class re_Test_Integer extends re_Scalar
{
	public function _declarePossRep(){
		
		return array(
			'decimal'=>array(
				'decimal'=>'' //'' means any type
			),
			'hex'=>array(
				'hex'=>''
			),
			'binary'=>array(
				'binary'=>''
			)
		);
	}
	
	protected function _decimal( $decimal ){
		
		$this->_setThe("decimal", $decimal);
	}
	
	protected function _hex( $hex ){
		
		$this->_decimal( hexdec($hex) );
	}
	
	protected function _binary( $binary ){
	
		$this->_decimal(bindec($binary));
	}
	
	public function thedecimal(){
		
		return $this->_getThe('decimal');
	}
	
	public function thehex(){
	
		return dechex($this->decimal);
	}
	
	public function thebinary(){
		return decbin($this->decimal);
	}

	//we define a simple operator "plus" (+) with the obvious semantics
	public function plus(re_Test_Integer $operand1){
		
		return re::select(
			get_class($this),
			$this->thedecimal() + $operand1->thedecimal(),
			'decimal'
		);
	}
	
	public function _sr( $recurse = FALSE ){
		
		return $this->theDecimal();
	}

	static public function _ss($rep){
		return re::select(__CLASS__, (integer)$rep, 'decimal');
	}
	
	public function _ssr(){
		return (double)$this->theDecimal();
	}
}